<%--
  Created by IntelliJ IDEA.
  User: 陌·笙
  Date: 2018-12-28
  Time: 18:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>库存报警</title>
    <jsp:include page="/comm/tag.jsp"/>
    <script>
        $(function () {
            $("#mytable").bootstrapTable({
                url: "/kucun/kucunbaojing",
                height: 730,
                pageSize: 12,
                pageNumber: 1,
                pageList: [4, 8, 10, 12],
                //启用分页，但是默认情况下，是客户端分页的
                pagination: true,
                sidePagination: 'server',
                queryParams: function (params) {
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        repertoryName: $("[name='repertoryName']").val(),
                        typeId: $("[name='typeId']").val(),
                        firmId: $("[name='firmId']").val(),
                    };
                    return temp;
                },
                locale: 'zh-CN',//中文支持,
                toolbar: '#top',
                columns: [
                    {
                        checkbox:true
                    },
                    {field: "repertoryId", title: "商品编号", align: "center"},
                    {field: "repertoryName", title: "商品名称", align: "center"},
                    {field: "model", title: "手机型号", align: "center"},
                    {field: "type.iptypeName", title: "手机类别", align: "center"},
                    {field: "repertoryNum", title: "当前库存", align: "center"},
                    {field: "price", title: "进价", align: "center"},
                    {field: "repertoryColor", title: "商品颜色", align: "center"},
                    {field: "repertoryRemark", title: "商品备注", align: "center"},
                    {field: "firm.firmName", title: "生产厂商", align: "center"},
                    {field: "lowest", title: "最低库存", align: "center"},
                    {field: "lack", title: "缺货", align: "center"},
                ]
            });
            $.ajax({
                url:"/role/showfirm",
                type:"get",
                success:function(data){
                    $.each(data,function(){
                        var adds=$("<option value='"+this.firmId+"'>"+this.firmName+"</option>");
                        $(".s").append(adds);
                    });
                }
            })
            $.ajax({
                url:"/type/showType",
                type:"get",
                success:function(data){
                    $.each(data,function(){
                        var adds=$("<option value='"+this.iptypeid+"'>"+this.iptypeName+"</option>");
                        $(".k").append(adds);
                    });
                }
            })
        })
        function  cha(){//查询
            var opts = $("#mytable").bootstrapTable("getOptions") ;
            var repertoryName=$("[name='repertoryName']").val();
            var typeId=$("[name='typeId']").val();
            var firmId=$("[name='firmId']").val();
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            $.ajax({
                url:"/kucun/kucunbaojing",
                type:"get",
                data:{"repertoryName":repertoryName,"typeId":typeId,'firmId':firmId,'limit':limit,'offset':offset},
                success:function(data){
                    $("#mytable").bootstrapTable("load",data);
                }
            })
        }
        function k(){
            var ids = "" ;//一个字符串
            var rows = $("#mytable").bootstrapTable("getSelections") ;
            if (rows.length==0){
                swal("错误！", "请选择要生成进货单的数据！", "error");
            }else{
                $.each(rows,function (index,row) {
                    ids = ids + row.repertoryId + "," ;
                    $.ajax({
                        type:"post",
                        url:"/kucun/upzt",
                        data:{"repertoryId":ids},
                        success:function(data){
                            if(data){
                                swal("成功", "已添加到进货单中！", "success");
                            }

                        }
                    })
                })
            }
        }
    </script>
</head>
<body>
<div style="margin-left: 50px;margin-right: 50px">
    <div class="#top" style="margin-top: 30px">
        <div class="col-md-1">
            <a href="/kucun/fileDownloadData" class="btn btn-primary"><span class="glyphicon glyphicon-save"></span>&nbsp;&nbsp;导出数据</a>
        </div>
        <div class="col-md-1">
            <button onclick="k()" class="btn btn-primary">生成进货单</button>
        </div>
        <div class="col-md-7">
            <form action="" method="post" role="form" class="form-horizontal">
                <div class="form-group col-md-4">
                    <label for="" class="col-md-4 control-label">商品名称:</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" name="repertoryName" placeholder="可模糊查询">
                    </div>
                </div>

                <div class="form-group col-md-4">
                    <label for="" class="col-md-4 control-label">商品类别:</label>
                    <div class="col-md-8">
                        <select name="typeId" id="inputID" class="form-control k">
                            <option value="0">全部</option>
                        </select>
                    </div>
                </div>
                <div class="form-group col-md-4">
                    <label for="" class="col-md-4 control-label">厂商:</label>
                    <div class="col-md-8">
                        <select name="firmId" id="firm" class="form-control s">
                            <option value="0">全部</option>
                        </select>
                    </div>
                </div>
                <button type="button" class="btn btn-primary btn-info glyphicon glyphicon-search" onclick="cha()">查询</button>
            </form>
        </div><%--搜索框--%>
    </div><%--搜索框--%>
    <table id="mytable"></table>
</div>
</body>
</html>
